package com.py.demo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @version 1.0
 * @Author: 许啸林 代理实现对象
 * @Date: 2021/6/7 16:36
 */
public class CustomProxyHandler implements InvocationHandler {
    /**
     * 使用构造函数构造代理对象
     */
    private Object object;

    public CustomProxyHandler(Object object) {
        this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理方法: " + method.getName() + " 参数列表: " + Arrays.toString(args));
        Object result = method.invoke(object, args);
        System.out.println("方法执行之后：" + object);
        return result;
    }
}
